#include "head.h"
#include "func.h"
int send_file_train(int fd_socket,char *filename){
    int fd=open(filename,O_RDONLY);
    off_t offset=0;
    recv(fd_socket,&offset,sizeof(offset),0);
    if(offset!=0){
        lseek(fd,offset,SEEK_SET);
    }
    train_t train;
    while(1){
        bzero(train._data,sizeof(train._data));
        train._data_len=read(fd,train._data,sizeof(train._data));
        if(train._data_len==0){
            send(fd_socket,&train._data_len,sizeof(train._data_len),0);
            close(fd);
            return 0;
        }
        ssize_t sret=send(fd_socket,&train,sizeof(train._data_len)+train._data_len,MSG_NOSIGNAL);
        if(sret==-1){
            printf("Disconnected.\n");
        }
    }
    close(fd);
    return 0;
}

